import { Inject, Controller, Get,Body,Put,UseGuard} from '@midwayjs/core';
import { Context } from '@midwayjs/koa';
import { UserService } from '../service/user.service';
import { UpdateUserDto } from '../dto/userDto';
import { AuthGuard }from '../gaurd/auth.guard';

@Controller('/user')
export class APIController {
  @Inject()
  ctx: Context;

  @Inject()
  userService: UserService;

/**
 * @name getUserinfo
 * @description Get /user/getUserinfo
 * @returns {object} 
 */
  @UseGuard(AuthGuard)
  @Get('/getUserinfo')
  async getUser():Promise<object> {
    const userId = this.ctx.user?.user_id; // 从 ctx.user 中获取用户 ID
    return await this.userService.getUserInfo(userId);
  }

/**
 * @name ifWgj
 * @description Get /user/ifWgj
 * @returns {object} 
 */
  @Get('/ifWgj')
  async ifWgj():Promise<object>{
    return await this.userService.isWgj(this.ctx.user?.user_id);
  }

/**
 * @name updateUser
 * @description Put /user/updateUser
 * @param {UpdateUserDto} userDate
 * @returns {object} 
 */
  @Put('/updateUser')
  async updateUser(@Body()userDate:UpdateUserDto):Promise<object>{
    const userId = this.ctx.user?.user_id; // 从 ctx.user 中获取用户 ID
    return await this.userService.updateUser(userId,userDate);
  }
}

